﻿/******************************************************************************
 * Copyright 2022-2032 ImperialVision Co., Ltd.
 * All right reserved. See COPYRIGHT for detailed Information.
 *
 * @file    ImageLabel.h
 * @brief   带缩放功能的图片标签
 * @usage   XXXX
 *
 * @author  linxiaohao<linxiaohao@imperial-vision.com>
 * @date    2022/12/22
 *****************************************************************************/
#ifndef IMAGELABEL_H
#define IMAGELABEL_H
#include <QLabel>
#include <QPainter>
#include <QWheelEvent>


class ImageLabel : public QLabel
{
public:
    ImageLabel(QWidget *parent = nullptr);

protected:
    void paintEvent(QPaintEvent *event) override;               //QPaint画图
    void wheelEvent(QWheelEvent *event) override;               //鼠标滚轮滚动
    void mousePressEvent(QMouseEvent *event) override;          //鼠标摁下
    void mouseMoveEvent(QMouseEvent *event) override;           //鼠标松开
    void mouseReleaseEvent(QMouseEvent *event) override;        //鼠标发射事件

public slots:
    void OnLoadImage(QImage image, double scale = 1.0); //加载图片
    QImage CurrentImage()const{return m_image;}
    void OnZoomInImage();       //图片放大
    void OnZoomOutImage();      //图片缩小
    void OnPresetImage();       //图片还原

private:
    QImage m_image;            //显示的图片
    qreal m_zoomValue;         //鼠标缩放值
    int m_xPtInterval;         //平移X轴的值
    int m_yPtInterval;         //平移Y轴的值
    QPoint m_oldPos;           //旧的鼠标位置
    bool m_isPressed;            //鼠标是否被摁压a
    bool mIsLoadingImage;
};

#endif //IMAGELABEL_H
